/**
 * 运营管理编辑员工
 */
import './index.less'
import tem from './index.html'
import $_fn from '~plugins'
import JSEncrypts from '~plugins/lib/js/jsencrypt.js'
class phoneCtrl {
  constructor($scope,$rootScope,http,$ui) {
  	  console.log($scope.params)
      $scope.cancel = function () {
      	  console.log('关闭')
          $rootScope.$uiDirectiveModal.close() //关闭方法
      }
    var encrypt1 = new JSEncrypts.JSEncrypt();//公钥对象
	var encrypt2 = new JSEncrypts.JSEncrypt();//私钥对象
	//公钥
	encrypt1.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCo9yyyvSUdMIu+Q3FniJuzFSfYyOc0UHZ/JGyWqwTlIgWxyAm6AcyRTzP//L6JdQ6+u8QSRWTmWW+dMSeGm0tYVAobGvTGG1eIduhE1RMqGYDbHzlCzTgkfvMIEpRncjzQYMDtlXH+i+sVeIEgM+eJnnCgRte5vicHKKkFmlg8LQIDAQAB");
	//私钥
	encrypt2.setPrivateKey('MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKfrKjZyCf8tI52u6LEwLMgmOKdNhqjVrNhnL3c9+pU0KRYKQrmDDf7R/jI7ZTI92luTUFw4PF1AJJgkgMRWQveZryD465lLX2M+Y6QasMk/VOJtdU+iZ1TQOeCzS//Hr3GpRYHUL6Q2oUsoDRgP+bvi13ypS8BnlvhxCxyCZi2VAgMBAAECgYBurd2kB2S5ckpAe/JaIBPUVQUQmVQB4t1Lwi+SHCMXx0qxgU/bsRs/c7Bl8apRBF3x8FaOgm6fVFEKizzorKb0M8MiHhp5FjLmg5+lPMgylaYSBQbEckFGBtPx5LXG+LdRU+VIi+RJtye4xzk2URSOk6iBBuykWknZpBlrcJ9e4QJBAOck0+PaZUjbaAf2y4e6i21OPkyqkbf58R0rmva9WVcXX3rgQtj5qXJqcB501NlLaz2fVb1cwcoxqyVCM63OGckCQQC5+c5MexsOU6pi15YJWw1fnrsOeA+Lg0MLcn6N7MGgfrG2Bygobgb6X1tKKAbAWbl5n+4UXvWQ0yKaXiAkBRttAkAFxgi450qiYECf+k0pLcKvz0WFGrmbE9Yu+Vjckuw5Xa8X3aQt0UanQftc92QdrWGXX3R/z2JTz5vLyXSLAdvpAkBfz11Ds4xNxjaac1x9d2YdY+YUXzAK/NW2eQbP0TAzofGlyGwc4ApCRIwAWTyZLeBK02TRI9a5BLzn8CP4ypTFAkEAq4tAs14vKDlR97V85Tq5mUXoAjEO2I2rFX+44uqkXlESkhStW2ML93j9ziU8HMhoETQ287Ze7hTYiLv4h54E1g==')

	//参数加密
    $scope.jiaMi=function(param){
    	for(name in param){
			param[name]=encrypt1.encrypt(param[name]+'')
		}
    }
    var creditUrl='http://192.168.1.176:8080/sys/'
    //参数解密
    $scope.jieMi=function(data){
    	var datas=[]
		for(var i=0; i<data.content.length; i++){
			console.log(data.content[i])
			console.log(encrypt2.decrypt(data.content[i]))
			datas.push(encrypt2.decrypt(data.content[i]))
		}
		console.log(datas)
		console.log(datas.join('\"'))
		var dataObj=JSON.parse(datas.join('\"'))
		//$scope.url1=creditUrl+dataObj.url+'?id='+dataObj.freepid+"&&code="+encrypt1.encrypt($scope.param.companycode.code)+"&&cid="+encrypt1.encrypt($scope.param.companycode.company_id+'');
		//return creditUrl+dataObj.url+'?id='+dataObj.freepid;
		return dataObj
    }
     console.log($scope.params)
     $scope.isShow=$scope.params.isShow;
     $scope.param1={
     	phone:$scope.params.phone,
     	msg:$scope.params.msg
     }
     console.log($scope.param1)
     //我知道了
     $scope.zhiDao1=function(){
     	$scope.isShow="mima"
     }
     
     $scope.zhiDao2=function(){
     	$scope.param2={
	     	account:$scope.params.phone,
	     	password:$scope.password,
	     	website:$scope.params.msg,
	     	cid:$scope.params.cid,
	     	code:$scope.params.code
	     }
     	$scope.jiaMi($scope.param2)
		console.log($scope.param2)
		http.post1('queryCreditAccessToken2',$scope.param2,function (data) {
			console.log(data)
            if(data.type == 1){
               // $scope.data2=$scope.jieMi(data)
                console.log(data)
                $scope.isShow="yanZheng"
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
        },false)
		/*console.log('------')
		if($scope.url1){
			window.open($scope.url1);
		}*/
     }
     //返回上一步
     $scope.shang1=function(){
     	$scope.isShow="mima"
     }
     
     //下一步
     $scope.xia2=function(){
     	$scope.param3={
	     	account:$scope.params.phone,
	     	password:$scope.password,
	     	website:$scope.params.msg,
	     	captcha:$scope.captcha,
	     	cid:$scope.params.cid,
	     	code:$scope.params.code
	     }
     	$scope.jiaMi($scope.param3)
		console.log($scope.param3)
		http.post1('queryCreditAccessToken3',$scope.param3,function (data) {
			console.log(data)
            if(data.type == 1){
               $scope.data3=data
                console.log($scope.data3)
                $scope.isShow="jinDong"
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
        },false)
     }
     $scope.param4={}
     $scope.xia3=function(){
     	$scope.param4.cid=$scope.params.cid;
     	$scope.param4.code=$scope.params.code;
     	$scope.param4.account=$scope.param5.account;
     	$scope.param4.password=$scope.param5.password
     	$scope.jiaMi($scope.param4)
		console.log($scope.param4)
		http.post1('queryCreditAccessToken4',$scope.param4,function (data) {
			console.log(data)
            if(data.type == 1){
              /* $scope.data4=$scope.jieMi(data)
                console.log($scope.data4)*/
               $scope.param6={
					phone:$scope.params.phone,
					idcard:$scope.params.idcard,
					name:$scope.params.name,
					code:$scope.params.code,
					cid:$scope.params.cid
				}
               $scope.jiaMi($scope.param6)
               http.post1('queryAccessReportData1',$scope.param6,function (_data) {
						console.log(data)
			            if(data.type == 1){
			            	$scope.data5=$scope.jieMi(_data)
			                $scope.url2=creditUrl+$scope.data5.url+'?id='+$scope.data5.freepid;
			            }else{
			            	$ui.toast({
								text:data.errmsg,
								type:'warning'
							})
			            }
			        },function(){
			            //报错时
			            $scope.isData = true
			     },false)
                $scope.url2=creditUrl+$scope.data4.url+'?id='+$scope.data4.freepid;
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
        },false)
		if($scope.url2){
			window.open($scope.url2);
		}
     }
     //弹出框大小
     $('.modal-dialog').css('width','30%')
  	//添加职位
  	  /*$scope.tiJiao1=function(){
	  	  	if(!$scope.param1.name){
	  	  		$ui.toast({
					text:'请输入职位名',
					type:'warning',
					appendTo:'.phone'
				})
	  	  		return 
	  	  	}
  	  		http.post('insertPosition.do',$scope.param1,function (data) {
				if(data.errcode==1){
					$ui.toast({
						text:data.errmsg,
						type:'succeed'
					})
					$scope.cancel()
			        window.history.go(0)
				}else{
					$ui.toast({
						text:data.errmsg,
						type:'warning',
						appendTo:'.phone'
					})
				}
	        },function(_data){
	            console.log(_data);//报错
	      	})
  	  }*/
  }
}
phoneCtrl.$inject = ['$scope','$rootScope','http','$ui']
module.exports = angular.module('directive.phone', []).directive('phone', function() {
    return {
        template: tem,
        replace:true,
        controller: phoneCtrl,
        scope:{
        	params:"<"
        }
    }
}).name